
//
//  MainViewController.m
//  Weibo
//
//  Created by APPLE on 2/12/16.
//  Copyright © 2016 renzc. All rights reserved.
//

#import "MainViewController.h"
#import "HomeTableVC.h"
#import "MainNVC.h"
#import "MessageTableVC.h"
#import "DiscoverTableVC.h"
#import "ProFileTableVC.h"
#import "MainTabBar.h"

@interface MainViewController ()

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    //初始化自定义tabBar
    UITabBar *tabBar = [[MainTabBar alloc] init];
    [self setValue:tabBar forKey:@"tabBar"];
    
    [self addChildViewControllers];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)addChildViewControllers {
    
    [self addChildViewController:[[HomeTableVC alloc] init] title:@"首页" imageName:@"tabbar_home"];
    [self addChildViewController:[[MessageTableVC alloc] init] title:@"消息" imageName:@"tabbar_message_center"];
    [self addChildViewController:[[DiscoverTableVC alloc] init] title:@"发现" imageName:@"tabbar_discover"];
    [self addChildViewController:[[ProFileTableVC alloc] init] title:@"我" imageName:@"tabbar_profile"];
    
}

- (void)addChildViewController:(UIViewController *)vc title:(NSString *)title imageName:(NSString *)imageName {
    vc.title = title;
    //更改字体颜色
    NSDictionary *dict = @{NSForegroundColorAttributeName: [UIColor orangeColor]};
    [vc.tabBarItem setTitleTextAttributes:dict forState:UIControlStateSelected];
    //设置tabbaritem的图片及选中图片
    vc.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    vc.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",imageName]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [self addChildViewController:[[MainNVC alloc] initWithRootViewController:vc]];
}



@end
